  //BB_PositionInText
  //By: Tony Ringsmuth 12/27/17, 11:36:26

  //FUNCTION: 
  // 
  //--------------------------------------------------------------------------------
  //PARAMETERS


  //--------------------------------------------------------------------------------
  //REVISION HISTORY
  //12/27/17: New

  //--------------------------------------------------------------------------------
C_LONGINT($0)
C_TEXT($1)
C_TEXT($2)
C_LONGINT($3;$StartPosition)
C_LONGINT($4;$Opts)

If (Application version>="16@")
$0:=Position($1;$2;*)
Else 

  //BB_PositionInText(FindText;SourceText;{StartPosition};{Opts})->Position
  //Tony Ringsmuth  3/12/02
  //Part of the BB_Base Component, by Business Brothers.

  //--------------------------------------------------------------------------------
  //FUNCTION: 
  //Find the position of FindText in Source Text, and allow more robust options,
  //  such as "find backwards".
  //<Category Text>
  //--------------------------------------------------------------------------------

  //PARAMETERS
  //$0: Longint: The detected Starting position of FindText in SourceText
  //$1: Text: The search string that you want to find
  //$2: Text: The text that may contain FindText
  //$3: Longint: optional: Starting Position: Defaults to 1 if not passed.
  //   If Start Position is not specified, or is Zero, and searching backwards,
  //      then the search will begin from the end of the string.
  //$4: Longint: Bitwise options
  //   +1: Search Backwards
  //   +2: Case Sensative (faster)

  //--------------------------------------------------------------------------------
  //EXAMPLES

  //Example: PositionInText("in";"Find") ->2
  //Example: PositionInText("in";"Find in text") ->2
  //Example: PositionInText("in";"Find in text";3) ->6   (start looking at char 3)
  //Example: PositionInText("in";"Find in text";0;1) ->6   (Find Backwards)
  //--------------------------------------------------------------------------------
  //REVISION HISTORY
  //03/12/2002: New
  //09/13/2002: Fixed bugs, better documentation
  //12/06/2007: Revised Documentation
  //--------------------------------------------------------------------------------


C_LONGINT($i;$j;$Position;$Increment;$End;$MaxStart)

$StartPosition:=0
If (Count parameters>2)
If ($3#0)
$StartPosition:=$3
End if 
End if 

$opts:=0
If (Count parameters>3)
$opts:=$4
End if 
$SearchBackwards:=($opts ?? 0)  //+1
$CaseSensative:=($opts ?? 1)  //+2

If ($SearchBackwards)
$Increment:=-1
$End:=1
$MaxStart:=Length($2)-Length($1)+1
Case of 
: ($StartPosition=0)
$StartPosition:=$MaxStart
: ($StartPosition>$MaxStart)
$StartPosition:=$MaxStart
End case 
Else 
$Increment:=1
$End:=Length($2)-Length($1)+1
If ($StartPosition<1)
$StartPosition:=1
End if 
End if 

$0:=0
If (Length($1)<=Length($2))
If ($CaseSensative)
  //This is faster than non-case sensative.
For ($i;$StartPosition;$End;$Increment)
If (Character code($1[[1]])=Character code($2[[$i]]))

$Position:=$i
For ($j;2;Length($1))
If (Character code($1[[$j]])#Character code($2[[$i-1+$j]]))
$Position:=0
$j:=33000
End if 
End for   //$j
If ($Position>0)
If ($SearchBackwards)
$i:=0
Else 
$i:=33000
End if 
End if 

End if 
End for 

Else 

For ($i;$StartPosition;$End;$Increment)
If (($1[[1]])=($2[[$i]]))

$Position:=$i
For ($j;2;Length($1))
If (($1[[$j]])#($2[[$i-1+$j]]))
$Position:=0
$j:=33000
End if 
End for   //$j
If ($Position>0)
If ($SearchBackwards)
$i:=0
Else 
$i:=33000
End if 
End if 

End if 
End for 

End if 
$0:=$Position
End if 
  //

End if 